import { configureStore } from '@reduxjs/toolkit';
import projectReducer from './projectSlice';
import okrReducer from './okrSlice';

/**
 * Redux store 配置
 * 集中管理应用的所有状态
 */
export const store = configureStore({
  reducer: {
    /** 项目管理模块的状态 */
    project: projectReducer,
    /** OKR 管理模块的状态 */
    okr: okrReducer,
  },
  middleware: (getDefaultMiddleware) =>
    getDefaultMiddleware({
      serializableCheck: {
        // 忽略持久化相关的 action，避免序列化检查警告
        ignoredActions: ['persist/PERSIST', 'persist/REHYDRATE'],
      },
    }),
});

/**
 * 根状态类型
 * 从 store 推断出的完整状态树类型
 */
export type RootState = ReturnType<typeof store.getState>;

/**
 * 应用 dispatch 类型
 * 包含所有 thunk action 的 dispatch 类型
 */
export type AppDispatch = typeof store.dispatch;
